﻿Imports System.Data
Imports ADOEntity
Imports ADOEntityImportData
Partial Class KYC_MasterPageKYC
   
    Inherits System.Web.UI.MasterPage
    Dim clsMenuRight As New clsSessionMenuRight
    Dim userEntity As UserEntities
    Dim tempClsChkIsPwdExp As String
    Dim importDataEntity As ImportDataEntity


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("Expires", "0")

        clsMenuRight = Session("ClsMenuRight")

        'If (Not IsPostBack) Then

        If Not (Session("ClsMenuRight") Is Nothing) Then
            lblDate.Text = clsMenuRight.getDateTimeLogin
            If Not clsMenuRight.getIsPwdExpire = 1 Then
                If Not clsMenuRight.getMustChangePwd = 1 Then
                    userEntity = New UserEntities

                    lblUser.Text = clsMenuRight.getUserName & " / " & clsMenuRight.getBranchCode

                    Dim qryMenuIsShow = (From smenuright In userEntity.SMENURIGHT Where smenuright.USERRIGHT = clsMenuRight.getUserRight And smenuright.ISSHOW = True).ToList

                    Dim intCountMenu As Integer = qryMenuIsShow.Count
                    Dim namePg As String = ""

                    For count As Integer = 0 To intCountMenu - 1
                        namePg = qryMenuIsShow(count).PROGRAMCODE

                        'เงินฝาก
                        If (namePg.Contains("M11")) Or (namePg.Contains("M12")) Then
                            ASPxMenu1.Items(0).Enabled = True
                            ASPxMenu1.Items(0).Visible = True
                            If (namePg.Contains("M11")) Then
                                ASPxMenu1.Items(0).Items(0).Enabled = True
                                ASPxMenu1.Items(0).Items(0).Visible = True
                            ElseIf (namePg.Contains("M12")) Then
                                ASPxMenu1.Items(0).Items(1).Enabled = True
                                ASPxMenu1.Items(0).Items(1).Visible = True
                            End If
                        ElseIf (namePg.Contains("M21")) Or (namePg.Contains("M22")) Then 'สินเชื่อ
                            ASPxMenu1.Items(1).Enabled = True
                            ASPxMenu1.Items(1).Visible = True
                            If (namePg.Contains("M21")) Then
                                ASPxMenu1.Items(1).Items(0).Enabled = True
                                ASPxMenu1.Items(1).Items(0).Visible = True
                            ElseIf (namePg.Contains("M22")) Then
                                ASPxMenu1.Items(1).Items(1).Enabled = True
                                ASPxMenu1.Items(1).Items(1).Visible = True
                            End If
                        ElseIf (namePg.Contains("M31")) Or (namePg.Contains("M32")) Then 'ตั๋ว
                            ASPxMenu1.Items(2).Enabled = True
                            ASPxMenu1.Items(2).Visible = True
                            If (namePg.Contains("M31")) Then
                                ASPxMenu1.Items(2).Items(0).Enabled = True
                                ASPxMenu1.Items(2).Items(0).Visible = True
                            ElseIf (namePg.Contains("M32")) Then
                                ASPxMenu1.Items(2).Items(1).Enabled = True
                                ASPxMenu1.Items(2).Items(1).Visible = True
                            End If
                        ElseIf (namePg.Contains("M33")) Or (namePg.Contains("M34")) Then 'NPA
                            ASPxMenu1.Items(3).Enabled = True
                            ASPxMenu1.Items(3).Visible = True
                            If (namePg.Contains("M33")) Then
                                ASPxMenu1.Items(3).Items(0).Enabled = True
                                ASPxMenu1.Items(3).Items(0).Visible = True
                            ElseIf (namePg.Contains("M34")) Then
                                ASPxMenu1.Items(3).Items(1).Enabled = True
                                ASPxMenu1.Items(3).Items(1).Visible = True
                            End If
                        ElseIf (namePg.Contains("M41")) Or (namePg.Contains("M42")) Or (namePg.Contains("M43")) Or (namePg.Contains("M44")) Or (namePg.Contains("M45")) Or (namePg.Contains("M46")) Or (namePg.Contains("M47")) Or (namePg.Contains("M48")) Or (namePg.Contains("M49")) Then 'KYC
                            ASPxMenu1.Items(4).Enabled = True
                            ASPxMenu1.Items(4).Visible = True
                            If (namePg.Contains("M41")) Then
                                ASPxMenu1.Items(4).Items(0).Enabled = True
                                ASPxMenu1.Items(4).Items(0).Visible = True
                            ElseIf (namePg.Contains("M42")) Then
                                ASPxMenu1.Items(4).Items(1).Enabled = True
                                ASPxMenu1.Items(4).Items(1).Visible = True
                            ElseIf (namePg.Contains("M43")) Then
                                ASPxMenu1.Items(4).Items(2).Enabled = True
                                ASPxMenu1.Items(4).Items(2).Visible = True
                            ElseIf (namePg.Contains("M44")) Then
                                ASPxMenu1.Items(4).Items(3).Enabled = True
                                ASPxMenu1.Items(4).Items(3).Visible = True
                            ElseIf (namePg.Contains("M45")) Then
                                ASPxMenu1.Items(4).Items(4).Enabled = True
                                ASPxMenu1.Items(4).Items(4).Visible = True
                            ElseIf (namePg.Contains("M46")) Then
                                ASPxMenu1.Items(4).Items(5).Enabled = True
                                ASPxMenu1.Items(4).Items(5).Visible = True
                            ElseIf (namePg.Contains("M47")) Then
                                ASPxMenu1.Items(4).Items(6).Enabled = True
                                ASPxMenu1.Items(4).Items(6).Visible = True
                            ElseIf (namePg.Contains("M48")) Then
                                ASPxMenu1.Items(4).Items(7).Enabled = True
                                ASPxMenu1.Items(4).Items(7).Visible = True
                            ElseIf (namePg.Contains("M49")) Then
                                ASPxMenu1.Items(4).Items(8).Enabled = True
                                ASPxMenu1.Items(4).Items(8).Visible = True
                            End If
                        ElseIf (namePg.Contains("M51")) Or (namePg.Contains("M52")) Or (namePg.Contains("M53")) Or (namePg.Contains("M54")) Or (namePg.Contains("M57")) Or (namePg.Contains("M58")) Then  'AMLO
                            'Or (namePg.Contains("M55")) Or (namePg.Contains("M56"))
                            ASPxMenu1.Items(5).Enabled = True
                            ASPxMenu1.Items(5).Visible = True
                            If (namePg.Contains("M51")) Then
                                ASPxMenu1.Items(5).Items(0).Enabled = True
                                ASPxMenu1.Items(5).Items(0).Visible = True
                            ElseIf (namePg.Contains("M52")) Then
                                ASPxMenu1.Items(5).Items(1).Enabled = True
                                ASPxMenu1.Items(5).Items(1).Visible = True
                            ElseIf (namePg.Contains("M53")) Then
                                ASPxMenu1.Items(5).Items(2).Enabled = True
                                ASPxMenu1.Items(5).Items(2).Visible = True
                            ElseIf (namePg.Contains("M57")) Then
                                ASPxMenu1.Items(5).Items(3).Enabled = True
                                ASPxMenu1.Items(5).Items(3).Visible = True
                            ElseIf (namePg.Contains("M54")) Then
                                ASPxMenu1.Items(5).Items(4).Enabled = True
                                ASPxMenu1.Items(5).Items(4).Visible = True
                                'ElseIf (namePg.Contains("M55")) Then
                                '    ASPxMenu1.Items(4).ChildItems(4).Enabled = True
                                'ElseIf (namePg.Contains("M56")) Then
                                '    ASPxMenu1.Items(4).ChildItems(5).Enabled = True
                            ElseIf (namePg.Contains("M58")) Then
                                ASPxMenu1.Items(5).Items(5).Enabled = True
                                ASPxMenu1.Items(5).Items(5).Visible = True
                            End If
                        ElseIf (namePg.Contains("M61")) Or (namePg.Contains("M62")) Or (namePg.Contains("M64")) Or (namePg.Contains("M65")) Or (namePg.Contains("M66")) Or (namePg.Contains("M67")) Or (namePg.Contains("M69")) Or (namePg.Contains("M71")) Or (namePg.Contains("M72")) Or (namePg.Contains("M73")) Then 'System
                            ASPxMenu1.Items(6).Enabled = True
                            ASPxMenu1.Items(6).Visible = True
                            If (namePg.Contains("M61")) Then
                                ASPxMenu1.Items(6).Items(0).Enabled = True
                                ASPxMenu1.Items(6).Items(0).Visible = True
                            ElseIf (namePg.Contains("M62")) Then
                                ASPxMenu1.Items(6).Items(1).Enabled = True
                                ASPxMenu1.Items(6).Items(1).Visible = True
                            ElseIf (namePg.Contains("M64")) Then
                                ASPxMenu1.Items(6).Items(2).Enabled = True
                                ASPxMenu1.Items(6).Items(2).Visible = True
                            ElseIf (namePg.Contains("M69")) Then
                                ASPxMenu1.Items(6).Items(3).Enabled = True
                                ASPxMenu1.Items(6).Items(3).Visible = True
                            ElseIf (namePg.Contains("M65")) Then
                                ASPxMenu1.Items(6).Items(4).Enabled = True
                                ASPxMenu1.Items(6).Items(4).Visible = True
                            ElseIf (namePg.Contains("M66")) Then
                                ASPxMenu1.Items(6).Items(5).Enabled = True
                                ASPxMenu1.Items(6).Items(5).Visible = True
                            ElseIf (namePg.Contains("M67")) Then
                                ASPxMenu1.Items(6).Items(6).Enabled = True
                                ASPxMenu1.Items(6).Items(6).Visible = True
                            ElseIf (namePg.Contains("M71")) Then
                                ASPxMenu1.Items(6).Items(7).Enabled = True
                                ASPxMenu1.Items(6).Items(7).Visible = True
                            ElseIf (namePg.Contains("M72")) Then
                                ASPxMenu1.Items(6).Items(8).Enabled = True
                                ASPxMenu1.Items(6).Items(8).Visible = True
                            ElseIf (namePg.Contains("M73")) Then
                                ASPxMenu1.Items(6).Items(9).Enabled = True
                                ASPxMenu1.Items(6).Items(9).Visible = True
                            End If
                        End If

                    Next

                    SetLinkManual()
                    userEntity = Nothing
                    clsMenuRight = Nothing
                Else
                    lblUser.Text = clsMenuRight.getUserName & " / " & clsMenuRight.getBranchCode
                End If
            End If
        Else
            Response.Redirect("~/KYC/index.aspx?SessionOut=1")
        End If
        'Else
        'If Session("ClsMenuRight") Is Nothing Then
        '    Response.Redirect("~/KYC/index.aspx?SessionOut=1")
        'End If
        'End If
    End Sub

    Protected Sub Menu1_MenuItemClick(ByVal source As Object, ByVal e As DevExpress.Web.ASPxMenu.MenuItemEventArgs) Handles ASPxMenu1.ItemClick
        If (e.Item.Name = "PG008") Then
            clsMenuRight = Session("ClsMenuRight")
            Session.Abandon()
            ' Session.Clear()
            Response.Redirect("~/KYC/index.aspx")
        End If
    End Sub

    Public Sub SetLinkManual()
        Dim path As String = System.Configuration.ConfigurationManager.AppSettings("Path_DOC_MANUAL")
        Dim url As String = Me.Request.RawUrl.Replace(Me.Request.ApplicationPath, "")
        importDataEntity = New ImportDataEntity()

        Dim fileName = (From doc In importDataEntity.KYC_USER_MANUAL Where doc.URL = url Select doc.FILE_NAME).ToList
        If (fileName.Count > 0) Then
            linkManual.NavigateUrl = System.IO.Path.Combine(path, fileName(0))
            linkManual.Visible = True
        Else
            linkManual.Visible = False
        End If

        importDataEntity = Nothing
    End Sub
End Class

